/*****************************************************************************
 *   i2ctest.c:  main C entry file for NXP LPC11xx Family Microprocessors
 *
 *   Copyright(C) 2008, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2009.12.07  ver 1.00    Preliminary version, first Release
 *
******************************************************************************/
#include "LPC134x.h"			/* LPC11xx Peripheral Registers */
#include "type.h"
#include "../core/i2c.h"
#include "../core/systick.h"
#include "../core/softspi.h"
#include "../core/gpio.h"
#include "../driver/ds1307.h"
#include "../driver/tsl2550.h"
#include "../driver/lm75b.h"
#include "../driver/as1107.h"
#include "../core/gpio.h"
#include "../core/timer16.h"
#include "../core/timer32.h"

#define MC24LC08_ADDR 0xa0		/* I2C address of the 24LC08 EEPROM */

/*******************************************************************************
**   Main Function  main()
*******************************************************************************/
int main (void)
{
	  /* Basic chip initialization is taken care of in SystemInit() called
	   * from the startup code. SystemInit() and chip settings are defined
	   * in the CMSIS system_<part family>.c file.
	   */
  uint8_t index;
  gpioInit();
  init_spi ();
  ds1307Init();
  //systickInit(CFG_SYSTICK_DELAY_IN_MS);     // Start systick timer
  tsl2550Init();
  lm75bInit();
  as1107Init();
//  as1107Test();
  // Set the time to 31 December 2012 @ 10:05:30
  //ds1307SetTime(13, 1, 1, 1, 17, 6, 30);

  uint32_t lux;
  ds1307Time_t time;
  int32_t temp = 0;
//  uint8_t i;
  uint32_t j;

  while(1) {
	  ds1307GetTime(&time);
	  lux = tsl2550GetLux();
      lm75bGetTemperature(&temp);
//      // Multiply value by 125 for fixed-point math (0.125°C per unit)
      temp *= 125;

//	  for (i = 0; i < 0xf;i++) {
		  for (index = 0; index < 0xf; index++) {
//			 as1107SetBrightness(i);
			 as1107WriteCmdData (AS1107_DIGIT0, index);
			 as1107WriteCmdData (AS1107_DIGIT1, index);
			 as1107WriteCmdData (AS1107_DIGIT2, index);
			 as1107WriteCmdData (AS1107_DIGIT3, index);
			 as1107WriteCmdData (AS1107_DIGIT4, index);
			 as1107WriteCmdData (AS1107_DIGIT5, index);
			 as1107WriteCmdData (AS1107_DIGIT6, index);
			 as1107WriteCmdData (AS1107_DIGIT7, index);
			 for (j=0;j< 0xffff; j++)
			 {
				 //do nothing
			 }
		  }
//	  }

	  //


	  printf("DW:%d, Y:%d, M:%d, D:%d, H:%d, M:%d, S:%d ,lux %d, Temperatur %d.%d  \r\n",
			  	  time.dayofweek, time.year, time.month, time.day, time.hour, time.minute, time.second,
			  	  lux,
			  	  temp/1000, temp % 1000);
  }



}

/******************************************************************************
**                            End Of File
******************************************************************************/
